<template>
  <div>
    <el-row class="box">
      <el-form label-position="right" label-width="110px">
        <el-col :span="8">
          <el-form-item label="任务编号:">
            <el-input v-model="form.id"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="任务分配状态:">
            <el-select v-model="form.assignedStatus" placeholder="请选择">
              <el-option
                  v-for="item in assignedStatus"
                  :key="item.value"
                  :label="item.lable"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="满载状态:">
            <el-select v-model="form.loadingStatus" placeholder="请选择">
              <el-option
                  v-for="item in loadingStatus"
                  :key="item.value"
                  :label="item.lable"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="车牌号码:">
            <el-input v-model="form.licensePlate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="起始地机构:">
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="目的地机构:">
          </el-form-item>
        </el-col>
        <el-button type="warning" plain @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form>
    </el-row>
    <el-row class="centen">
      <el-col :span="2"
      ><el-button
      >全部 {{counts1}}</el-button
      ></el-col
      >
      <el-col :span="2"
      ><el-button @click="gettaskManagerPage(form, 1)"
      >待提货{{counts2}}</el-button
      ></el-col
      >
      <el-col :span="2"
      ><el-button @click="gettaskManagerPage2">进行中{{counts3}}</el-button>
      </el-col>
      <el-col :span="2"
      ><el-button @click="gettaskManagerPage4">已完成{{counts4}}</el-button>
      </el-col>
      <el-col :span="2"
      ><el-button @click="gettaskManagerPage5">已取消{{counts5}}</el-button>
      </el-col>
    </el-row>
    <div class="button">
      <el-table :data="Data" style="width: 100%; font-size: 12px" v-loading="loading">
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="id" label="运输任务编号" width="180">
        </el-table-column>
        <el-table-column prop="truck.licensePlate" label="车牌号码" width="100">
        </el-table-column>
        <el-table-column prop="startAgency.name" label="起始地" width="150">
        </el-table-column>
        <el-table-column prop="endAgency.name" label="目的地" width="150">
        </el-table-column>
        <el-table-column
            prop="status"
            label="运输任务状态"
            width="120"
        >
          <template #default="{row}">
            {{foreee(row.status)}}
          </template>
        </el-table-column>
        <el-table-column
            prop="loadingStatus"
            label="车辆装载状态"
            width="120"
        >
          <template #default="{row}">
            {{foreee1(row.loadingStatus)}}
          </template>
        </el-table-column>
        <el-table-column
            prop="assignedStatus"
            label="任务分配状态"
            width="120"
        >
          <template #default="{row}">
            {{foreee2(row.assignedStatus)}}
          </template>
        </el-table-column>
        <el-table-column
            prop="planDepartureTime"
            label="计划发车时间"
            width="160"
        >
        </el-table-column>
        <el-table-column
            prop="actualDepartureTime"
            label="实际发车时间"
            width="160"
        >
        </el-table-column>
        <el-table-column prop="updated" label="更新时间" width="160">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template #default="{ row }">
            <el-button
                type="text"
                size="small"
                @click="
                $router.push({
                  path: '/transit/talk',
                  query: { id: row.id, type: '运输管理' },
                })
              "
            >查看</el-button
            >
            <el-button
                :disabled="row.status !== 1"
                @click="cancel"
                type="text"
                size="small"
            >取消</el-button
            >
            <el-button
                :disabled="row.status !== 1"
                @click="shoudong(row)"
                type="text"
                size="small"
            >手动调整</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @current-change="handleCurrentChange"
          :page-size="form.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
      >
      </el-pagination>
    </div>
    <el-dialog
        title="手动调整"
        :visible.sync="dialogshow"
        width="40%"
        @close="handleClose"
    >
      <el-form label-position="right" label-width="100px">
        <el-form-item label="任务编号：">
          <el-input v-model="carform.id"></el-input>
        </el-form-item>
        <el-form-item label="运单数量：">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="选择车次：">
          <el-select
              v-model="carform.transportTripsId"
              placeholder="请选择"
          >
            <el-option
                v-for="item in carList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择车辆：">
          <el-select v-model="carform.truckId" placeholder="请选择">
            <el-option
                v-for="item in car"
                :key="item.id"
                :label="item.licensePlate"
                :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogshow = false">取 消</el-button>
        <el-button type="primary" @click="putAdjust">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {gettransportApi, gettreeLIst1, putAdjustApi} from "@/api/task";
const map= {
  4:'已完成',
  5:'未完成'
}
const map1= {
  2:'满载',
  3:'空载'
}
const map2={
  2:'已分配',
  3:'未分配'
}

export default {
  name: "transport-task",
  data() {
    return {
      counts1:'',
      counts2:'',
      counts3:'',
      counts4:'',
      counts5:'',
      form: {
        id: "",
        page: 1,
        pageSize: 10,
        loadingStatus: "",
        assignedStatus: "",
        licensePlate: "",
      },
      Data: [{}],
      total: 0,
      loading:false,
      assignedStatus: [
        {
          lable: "未分配",
          value: 1,
        },
        {
          lable: "已分配",
          value: 2,
        },
        {
          lable: "待人工分配",
          value: 3,
        },
      ],
      loadingStatus: [
        {
          lable: "满载",
          value: 2,
        },
        {
          lable: "空载",
          value: 3,
        },
      ],
      carList: [],
      car: [],
      dialogshow: false,
      carform: {
        id: "",
        driverId: "",
        truckId: "",
        transportTripsId: "",
      },
    };
  },
  created() {
    this.gettransport()
  },
  methods: {
    async gettransport() {
      this.loading=true
      const res = await gettransportApi(this.form)
      // console.log(res)
      this.Data=res.data.items
      this.total=+res.data.counts
      this.counts1=+res.data.counts||0
      const res1 = await gettransportApi({...this.form,status:1})
      this.counts2=+res1.data.counts||0
      const res2 = await gettransportApi({...this.form,status:2})
      this.counts3=+res2.data.counts||0
      const res3 = await gettransportApi({...this.form,status:3})
      this.counts4=+res3.data.counts||0
      const res4 = await gettransportApi({...this.form,status:4})
      this.counts4=+res4.data.counts||0
      const res5 = await gettransportApi({...this.form,status:5})
      this.counts5=+res5.data.counts||0
      this.loading=false
    },
    foreee(e) {
      return map[e]
    },
    foreee1(e) {
      return map1[e]
    },
    foreee2(e) {
      return map2[e]
    },
    async gettaskManagerPage2() {
      const res3 = await gettransportApi({...this.form,status:3})
      this.Data=res3.data.items
      this.total=+res3.data.counts
    },
    async gettaskManagerPage4 () {
      const res = await gettransportApi({...this.form,status:4})
      this.Data=res.data.items
      this.total=+res.data.counts
    },
    async gettaskManagerPage() {
      this.loading=true
      const res = await gettransportApi({...this.form,status:1})
      console.log(res)
      this.Data=res.data.items
      this.total=+res.data.counts
      this.counts2=+res.data.counts
      this.loading=false
    },
    async gettaskManagerPage5 () {
      const res = await gettransportApi({...this.form,status:5})
      this.Data=res.data.items
      this.total=+res.data.counts
    },
    async search() {
      const res = await gettransportApi(this.form)
      console.log(res)
      this.Data=res.data.items
    },
    reset() {
      this.form={
        id: "",
        page: 1,
        pageSize: 10,
        loadingStatus: "",
        assignedStatus: "",
        licensePlate: "",
      }

    },
    async handleCurrentChange(e) {
     
    },
    handleClose() {

    },
    async putAdjust() {
      const res = await putAdjustApi(this.carform);
      console.log(res);
      this.$message.success("修改成功");
    },
    cancel() {},
    async shoudong() {
      this.dialogshow=true
      const res = await gettreeLIst1()
      console.log(res)
      this.carList=res.data
    }

  },

}
</script>

<style lang="scss" scoped>
.box {
  background-color: #fff;
  height: 204px;
  padding: 20px;
  margin-bottom: 20px;
  .el-col.el-col-8 {
    padding-right: 15px;
  }
}
.centen {
  height: 48px;
  margin-bottom: 20px;
  background-color: #fff;
  .el-col.el-col-2 {
    height: 100%;
    .el-button {
      width: 100%;
      height: 100%;
      border: 0px;
    }
  }
}
.button {
  background-color: #fff;
  padding: 20px;
}
</style>
